package com.anXin.mall.service.impl;

import com.anXin.mall.mapper.GoodsMapper;
import com.anXin.mall.service.GoodsService;
import com.anXin.model.common.dtos.ResponseResult;
import com.anXin.model.mall.pojos.Goods;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;


@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements GoodsService {


    @Override
    public ResponseResult<Page<Goods>> getGoodsPage(int page,int pageSize) {
        Page<Goods> pageInfo = new Page<>(page,pageSize);
        return ResponseResult.okResult(query().page(pageInfo));
    }

    @Override
    public ResponseResult<Goods> getGoods(Long id) {
        Goods goods = query().eq("id", id).one();
        return ResponseResult.okResult(goods);
    }

    @Override
    public ResponseResult<String> updataGoods(Goods goods) {
        if(goods.getId()!=null){
            updateById(goods);
        }else {
            save(goods);
        }
        return ResponseResult.okResult(200,"修改成功");
    }

    @Override
    public ResponseResult<String> deleteGoods(Long id) {
        removeById(id);
        return ResponseResult.okResult(200,"删除成功");
    }
}
